package rss_POJO;

import java.util.Date;
import java.util.Collection;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.persistence.CascadeType;

/**
 *
 * @author RS-team
 */
@Entity
@Table(name = "ARTIST")
//@Table(name = "ARTIST", uniqueConstraints = {
//    @UniqueConstraint(columnNames = {"ARTISTICNAME"})})
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Artist.findAll", query = "SELECT a FROM Artist a"),
    @NamedQuery(name = "Artist.findByArtistid", query = "SELECT a FROM Artist a WHERE a.artistid = :artistid"),
    @NamedQuery(name = "Artist.findByFirstname", query = "SELECT a FROM Artist a WHERE a.firstname = :firstname"),
    @NamedQuery(name = "Artist.findByLastname", query = "SELECT a FROM Artist a WHERE a.lastname = :lastname"),
    @NamedQuery(name = "Artist.findByArtisticname", query = "SELECT a FROM Artist a WHERE a.artisticname = :artisticname"),
    @NamedQuery(name = "Artist.findBySex", query = "SELECT a FROM Artist a WHERE a.sex = :sex"),
    @NamedQuery(name = "Artist.findByBirthdate", query = "SELECT a FROM Artist a WHERE a.birthdate = :birthdate"),
    @NamedQuery(name = "Artist.findByBirthplace", query = "SELECT a FROM Artist a WHERE a.birthplace = :birthplace")})
public class Artist implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "ARTISTID")  // είναι not nullable αλλά και unique ως primary key
        @Basic(optional = false)
        private Integer artistid;
    @Column(name = "FIRSTNAME", nullable = true, unique = false, length = 50)
        @Basic(optional = true)
        private String firstname;
    @Column(name = "LASTNAME", nullable = true, unique = false, length = 50)
        @Basic(optional = true)
        private String lastname;
    @Column(name = "ARTISTICNAME", nullable = false, unique = true, length = 101)  // μοναδικότητα κύριου αναγνωριστικού πεδίου αναζήτησης
        @Basic(optional = false)
        private String artisticname;
    @Column(name = "SEX", nullable = true, unique = false)
        @Basic(optional = true)
        private Integer sex;
    @Column(name = "BIRTHDATE", nullable = true, unique = false)
        @Basic(optional = true)
        @Temporal(TemporalType.DATE)
        private Date birthdate;
    @Column(name = "BIRTHPLACE", nullable = true, unique = false, length = 100)
        @Basic(optional = true)
        private String birthplace;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "artistId")
        private Collection<Album> albumCollection;
    @ManyToOne(optional = false)
        @JoinColumn(name = "MUSICGENRE_ID", referencedColumnName = "MUSICGENREID", nullable = false, unique = false)
        private MusicGenre musicgenreId;
    @ManyToMany(mappedBy = "artistCollection")
        private Collection<MusicGroup> musicGroupCollection;

    /* default constructor */
    public Artist() {
    }
    /* "τεμπέλικος" constructor χωρίς τα nullable πεδία */
    public Artist(String artisticname) {
        this.artistid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.artisticname = artisticname;
    }
    /* και ο πλήρης constructor */
    public Artist(String firstname, String lastname, String artisticname, Integer sex, Date birthdate, String birthplace) {
        this.artistid = null;  // ετσι κι αλλιώς θα το ορίσει η ΒΔ
        this.firstname = firstname;
        this.lastname = lastname;
        this.artisticname = artisticname;
        this.sex = sex;
        this.birthdate = birthdate;
        this.birthplace = birthplace;
    }

    /* getters */
    public Integer getArtistid() { return artistid; }
    public String getFirstname() { return firstname; }
    public String getLastname() { return lastname; }
    public String getArtisticname() { return artisticname; }
    public Integer getSex() { return sex; }
    public Date getBirthdate() { return birthdate; }
    public String getBirthplace() { return birthplace; }
    /* getter για foreign key */
    public MusicGenre getMusicgenreId() { return musicgenreId; }

    /* setters εκτός ίσως από το primary key */
    public void setArtistid(Integer artistid) { this.artistid = artistid; }
    public void setFirstname(String firstname) { this.firstname = firstname; }
    public void setLastname(String lastname) { this.lastname = lastname; }
    public void setArtisticname(String artisticname) { this.artisticname = artisticname; }
    public void setSex(Integer sex) { this.sex = sex; }
    public void setBirthdate(Date birthdate) { this.birthdate = birthdate; }
    public void setBirthplace(String birthplace) { this.birthplace = birthplace; }
    /* setter για foreign key */
    public void setMusicgenreId(MusicGenre musicgenreId) { this.musicgenreId = musicgenreId; }
    
    @XmlTransient
    /* getter και setter για την musicGroupCollection */
    public Collection<MusicGroup> getMusicGroupCollection() {
        return musicGroupCollection;
    }
    public void setMusicGroupCollection(Collection<MusicGroup> musicGroupCollection) {
        this.musicGroupCollection = musicGroupCollection;
    }

    @XmlTransient
    /* getter και setter για την albumCollection */
    public Collection<Album> getAlbumCollection() {
        return albumCollection;
    }
    public void setAlbumCollection(Collection<Album> albumCollection) {
        this.albumCollection = albumCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (artistid != null ? artistid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Artist)) {
            return false;
        }
        Artist other = (Artist) object;
        if ((this.artistid == null && other.artistid != null) || (this.artistid != null && !this.artistid.equals(other.artistid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "rss_POJO.Artist[ artistid=" + artistid + " ]";
    }

}